package com.leetcode.algorithm.y22.m07;

import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * 1346. 检查整数及其两倍数是否存在
 * 
 * https://leetcode.cn/problems/check-if-n-and-its-double-exist/
 * 
 * @author jie.deng
 *
 */
class Question1346Solution01 {
	
	public boolean checkIfExist(int[] arr) {
		Set<Integer> numSet = new HashSet<>();
		int zeroCnt = 0;
		for (int i = 0; i < arr.length; i++) {
			if (arr[i] == 0) {
				zeroCnt++;
				if (zeroCnt >= 2) {
					return true;
				}
			} else {
				numSet.add(arr[i]);
			}
		}
		for (int i = 0; i < arr.length; i++) {
			if (((arr[i] & 1) == 0) && numSet.contains(arr[i] >> 1)) {
				return true;
			}
		}
		return false;
	}
    
}